


data=importdata('C:\Users\g0901119\Desktop\analysis of tetramer folding DNA\extension.dat');
mydata=data.data;
extension_current=mydata(:2)
window_size=10;
threshold=10;
    for j=(window_size+1):(length(extension_current)-window_size)
        previous=mean(extension_current((j-window_size):j));
        later=mean(extension_current(j:(j+window_size)));
        step_diff_current=later-previous;
        if abs(step_diff_current)>threshold 
                flag_step=1;
        end
        if flag_step==1
            if abs(step_diff_current)<=threshold 
                flag_step=0;
                step_list=[step_list;[MagnetPositions(i,1) MagnetPositions(i,4) step_position step_diff_max]];
                if step_diff_max>0
                    unfold_list=[unfold_list;[MagnetPositions(i,1) MagnetPositions(i,4) step_position step_diff_max]];
                else
                    refold_list=[refold_list;[MagnetPositions(i,1) MagnetPositions(i,4) step_position abs(step_diff_max)]];
                end
                step_diff_max=0;
            else
                if abs(step_diff_current)>abs(step_diff_max)
                    step_diff_max=step_diff_current;
                    step_position=MagnetPositions(i,2)+j-1;
                end
            end
            
        end
    end
    
    X=[step_list(:,4) step_list(:,2)];
UNfold=[unfold_list(:,4) unfold_list(:,2)];
REfold=[refold_list(:,4) refold_list(:,2)];